/*
 * Copyright (c) 2006 - 2022, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * <p>Project: app2022 - T26
 * <p>Powered by webrx On 2022-02-07 17:40:25
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class T26 {
    static AtomicInteger i = new AtomicInteger();
    static CountDownLatch latch = new CountDownLatch(1000000);

    public static void main(String[] args) {
        long s = System.currentTimeMillis();
        System.out.println(s);
        var t = new T26();
        for (int i1 = 0; i1 < 1000000; i1++) {
            new Thread(t::add).start();
        }

        try {
            latch.await();
            System.out.println(i.get());
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println(System.currentTimeMillis() - s);


    }

    void add() {
        i.incrementAndGet(); //相当于 ++i
        //i.getAndIncrement()  i++
        latch.countDown();
    }
}
